home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / LockEmUp / LockemUp.jar / LockemUp / TitleScreen.class (.txt) < prev   
Encoding:
Java Class File  |  2002-03-05  |  5.1 KB  |  257 lines

  1. package LockemUp;
  2.  
  3. import com.siemens.mp.game.ExtendedImage;
  4. import com.siemens.mp.game.Melody;
  5. import com.siemens.mp.game.MelodyComposer;
  6. import javax.microedition.lcdui.Canvas;
  7. import javax.microedition.lcdui.CommandListener;
  8. import javax.microedition.lcdui.Font;
  9. import javax.microedition.lcdui.Graphics;
  10. import javax.microedition.lcdui.Image;
  11. import javax.microedition.lcdui.List;
  12.  
  13. public class TitleScreen extends BaseScreen {
  14.    private static final int GAME_SCREEN_WIDTH = 96;
  15.    private static final int GAME_SCREEN_HEIGHT = 80;
  16.    private static final int DISAPPEAR_TIMER = 1;
  17.    private static final String[] titles = new String[]{"res\\lock.bin", "res\\win.bin", "res\\lose.bin", "res\\help1.bin", "res\\help2.bin", "res\\help3.bin"};
  18.    private int mode;
  19.    private int timer;
  20.    private int state;
  21.    private boolean running;
  22.    private boolean readyToPaint;
  23.    private CommandListener listener;
  24.    private byte[][] pixels = new byte[2][];
  25.    private Image gameScreenImage;
  26.    private ExtendedImage gameScreen;
  27.    private boolean onSound;
  28.    private Melody melody;
  29.  
  30.    public TitleScreen() {
  31.       try {
  32.          this.gameScreenImage = Image.createImage(96, 80);
  33.          this.gameScreen = new ExtendedImage(this.gameScreenImage);
  34.          this.pixels[0] = ((BaseScreen)this).ReadByteArray(titles[1], 960, 0);
  35.          this.pixels[1] = ((BaseScreen)this).ReadByteArray(titles[2], 960, 0);
  36.          byte[] var1 = ((BaseScreen)this).ReadByteArray(titles[0], 960, 0);
  37.          this.gameScreen.setPixels(var1, 0, 0, 96, 80);
  38.       } catch (Exception var3) {
  39.          System.out.println("Exception: " + var3);
  40.       }
  41.  
  42.       this.readyToPaint = true;
  43.       this.timer = 1;
  44.       this.mode = 100;
  45.       this.state = 0;
  46.       this.onSound = true;
  47.       Object var4 = null;
  48.       this.melody = this.createMelody(100);
  49.       this.melody.play();
  50.    }
  51.  
  52.    public void changeMode(int var1, String var2, String var3) {
  53.       if (this.mode != 5) {
  54.          this.mode = var1;
  55.          if (this.mode < 2) {
  56.             this.gameScreen.setPixels(this.pixels[var1], 0, 0, 96, 80);
  57.             if (this.onSound) {
  58.                this.melody = this.createMelody(var1);
  59.                this.melody.play();
  60.             }
  61.  
  62.             if (this.mode == 0) {
  63.                Font var4 = Font.getFont(0, 1, 8);
  64.                this.gameScreenImage.getGraphics().setFont(var4);
  65.                this.gameScreenImage.getGraphics().drawString(var2, 51, 56, 20);
  66.                this.gameScreenImage.getGraphics().drawString(var3, 51, 68, 20);
  67.             }
  68.          } else if (this.mode < 5) {
  69.             byte[] var5 = ((BaseScreen)this).ReadByteArray(titles[this.mode + 1], 960, 0);
  70.             this.gameScreen.setPixels(var5, 0, 0, 96, 80);
  71.             Object var10 = null;
  72.          } else {
  73.             this.gameScreen.clear((byte)0);
  74.             Font var9 = Font.getFont(0, 1, 8);
  75.             this.gameScreenImage.getGraphics().setFont(var9);
  76.             int var11 = var9.stringWidth("Saving best...");
  77.             int var6 = var9.getHeight();
  78.             int var7 = (96 - var11) / 2;
  79.             int var8 = (80 - var6) / 2;
  80.             this.gameScreenImage.getGraphics().drawString("Saving best...", var7, var8, 20);
  81.             var7 -= 2;
  82.             var8 -= 2;
  83.             this.gameScreenImage.getGraphics().drawRect(var7, var8, var11 + 3, var6 + 3);
  84.             var7 -= 2;
  85.             var8 -= 2;
  86.             this.gameScreenImage.getGraphics().drawRect(var7, var8, var11 + 7, var6 + 7);
  87.          }
  88.  
  89.          this.gameScreen.blitToScreen(3, 0);
  90.          this.readyToPaint = true;
  91.          this.state = 0;
  92.       }
  93.    }
  94.  
  95.    public void setOnSound(boolean var1) {
  96.       this.onSound = var1;
  97.    }
  98.  
  99.    public void Dispose() {
  100.       this.gameScreen = null;
  101.       this.pixels = null;
  102.       this.melody = null;
  103.    }
  104.  
  105.    public void setStateValue(int var1) {
  106.       this.state = var1;
  107.       if (this.mode < 100) {
  108.          this.gameScreen.clear((byte)0);
  109.       }
  110.  
  111.       if (var1 < 4) {
  112.          Font var6 = Font.getFont(0, 1, 8);
  113.          this.gameScreenImage.getGraphics().setFont(var6);
  114.          if (this.mode < 100) {
  115.             int var2 = var6.stringWidth("Please wait...");
  116.             int var3 = var6.getHeight();
  117.             int var4 = (96 - var2) / 2;
  118.             int var5 = (80 - var3) / 2;
  119.             this.gameScreenImage.getGraphics().drawString("Please wait...", var4, var5, 20);
  120.             var4 -= 2;
  121.             var5 -= 2;
  122.             this.gameScreenImage.getGraphics().drawRect(var4, var5, var2 + 3, var3 + 3);
  123.             var4 -= 2;
  124.             var5 -= 2;
  125.             this.gameScreenImage.getGraphics().drawRect(var4, var5, var2 + 7, var3 + 7);
  126.          }
  127.       }
  128.  
  129.       this.gameScreen.blitToScreen(3, 0);
  130.    }
  131.  
  132.    public int getReturnValue() {
  133.       return this.state;
  134.    }
  135.  
  136.    public void run() {
  137.       this.running = true;
  138.  
  139.       while(this.running) {
  140.          try {
  141.             Thread.sleep(20L);
  142.             ((Canvas)this).repaint();
  143.          } catch (Exception var2) {
  144.             System.out.println("Exception: " + var2);
  145.          }
  146.  
  147.          if (this.state != 0) {
  148.             this.running = false;
  149.          } else if (this.mode > 99 && this.timer > 0) {
  150.             --this.timer;
  151.             if (this.timer <= 0) {
  152.                this.setStateValue(1);
  153.             }
  154.          }
  155.       }
  156.  
  157.    }
  158.  
  159.    public void paint(Graphics var1) {
  160.       if (this.gameScreen != null && this.readyToPaint) {
  161.          try {
  162.             this.gameScreen.blitToScreen(3, 0);
  163.          } catch (Exception var3) {
  164.             System.out.println("Exception: " + var3);
  165.          }
  166.       }
  167.  
  168.    }
  169.  
  170.    protected void keyPressed(int var1) {
  171.       if (var1 == -12) {
  172.          this.listener.commandAction(List.SELECT_COMMAND, this);
  173.       } else {
  174.          if (this.mode > 99) {
  175.             this.setStateValue(1);
  176.          } else if (this.mode >= 2 && this.mode <= 4) {
  177.             int var2 = ((Canvas)this).getGameAction(var1);
  178.             switch (var2) {
  179.                case 1:
  180.                case 2:
  181.                   this.prevHelp();
  182.                case 3:
  183.                case 4:
  184.                default:
  185.                   break;
  186.                case 5:
  187.                case 6:
  188.                   this.nextHelp();
  189.             }
  190.          }
  191.  
  192.       }
  193.    }
  194.  
  195.    public void setCommandListener(CommandListener var1) {
  196.       super.setCommandListener(var1);
  197.       this.listener = var1;
  198.    }
  199.  
  200.    public void nextHelp() {
  201.       if (this.mode < 4) {
  202.          this.changeMode(this.mode + 1, (String)null, (String)null);
  203.       }
  204.  
  205.    }
  206.  
  207.    public void prevHelp() {
  208.       if (this.mode > 2) {
  209.          this.changeMode(this.mode - 1, (String)null, (String)null);
  210.       }
  211.  
  212.    }
  213.  
  214.    private Melody createMelody(int var1) {
  215.       try {
  216.          MelodyComposer var2 = new MelodyComposer();
  217.          var2.setBPM(132);
  218.          switch (var1) {
  219.             case 0:
  220.                var2.appendNote(45, 5);
  221.                var2.appendNote(52, 5);
  222.                var2.appendNote(48, 5);
  223.                var2.appendNote(40, 5);
  224.                var2.appendNote(42, 5);
  225.                var2.appendNote(49, 5);
  226.                var2.appendNote(44, 5);
  227.                var2.appendNote(51, 5);
  228.                break;
  229.             case 1:
  230.                var2.appendNote(24, 5);
  231.                var2.appendNote(19, 5);
  232.                var2.appendNote(15, 5);
  233.                var2.appendNote(14, 5);
  234.                var2.appendNote(24, 5);
  235.                var2.appendNote(19, 5);
  236.                var2.appendNote(15, 5);
  237.                var2.appendNote(14, 5);
  238.                break;
  239.             case 100:
  240.                var2.appendNote(45, 5);
  241.                var2.appendNote(52, 5);
  242.                var2.appendNote(48, 5);
  243.                var2.appendNote(40, 5);
  244.                var2.appendNote(42, 5);
  245.                var2.appendNote(49, 5);
  246.                var2.appendNote(44, 5);
  247.                var2.appendNote(51, 5);
  248.          }
  249.  
  250.          return var2.getMelody();
  251.       } catch (Exception var3) {
  252.          System.out.println("Exception: " + var3);
  253.          return null;
  254.       }
  255.    }
  256. }
  257.